
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
    #region ShipMethod Model -(by fangyifeng at 2010-12-27 11:18:16)

    /// <summary>
    /// ShipMethod object'ShipMethod'.
    /// </summary>
    public class ShipMethod : System.IComparable
    {
        #region Member Variables

        protected Guid _id;
        protected string _methodName;
        protected string _memo;

        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public ShipMethod() { }

        public ShipMethod(string methodName, string memo)
        {
            this._methodName = methodName;
            this._memo = memo;
        }

        #endregion

        #region Public Properties

        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual string MethodName
        {
            get { return _methodName; }
            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for MethodName", value, value.ToString());
                _methodName = value;
            }
        }

        public virtual string Memo
        {
            get { return _memo; }
            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for Memo", value, value.ToString());
                _memo = value;
            }
        }

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is ShipMethod))
                throw new InvalidCastException("This object is not of type ShipMethod");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((ShipMethod)obj).Id);
                    break;
                case "MethodName":
                    relativeValue = this.MethodName.CompareTo(((ShipMethod)obj).MethodName);
                    break;
                case "Memo":
                    relativeValue = (this.Memo != null) ? this.Memo.CompareTo(((ShipMethod)obj).Memo) : -1;
                    break;
                default:
                    goto case "Id";
            }
            if (ShipMethod.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
